<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script>
	$(function(){
		$("#tab").idTabs();
	});
</script>
<h1><?php echo $fund['name'] ?></h1>
<ul id="breadcrumb">	
	<li><span>ใบสำคัญการลงบัญชี</span></li>	
</ul>
<div id="content">
		
	<ul id="tab" class="tab">
		<li><a href="#tab1">ปิดบัญชีรายได้และค่าใช้จ่ายเข้าบัญชีรายได้สูง/(ต่ำ) กว่าค่าใช้จ่าย</a></li>
		<li><a href="#tab2">ปิดบัญชีรายได้สูง/(ต่ำ) กว่าค่าใช้จ่ายเข้าบัญชีรายได้สูง/(ต่ำ)กว่าค่าใช้จ่ายสะสม</a></li>
	</ul>
	<div id="tab1">
	<table class="form">
		<tr><th>วันเดือนปีที่ลงบัญชี</th><td><?php echo db_to_th($voucher1['voucher_date']) ?></td></tr>
		<tr><th>เลขที่</th><td><?php echo $voucher1['number'] ?></td></tr>
		<tr>
			<th>ประเภท</th>
			<td>
				<?php echo ($voucher1['voucher_type_id']==1)?'ด้านรับ':'' ?>
				<?php echo ($voucher1['voucher_type_id']==2)?'ด้านจ่าย':'' ?>
				<?php echo ($voucher1['voucher_type_id']==3)?'ด้านทั่วไป':'' ?>
			</td>
		</tr>
		<tr><th>รายการการลงบัญชี</th><td class="voucher_match"></td></tr>
		<tr>
			<th colspan="2" style="background:#EEE;">
				<div id="voucher_match">
				<table class="tbform">
					<tr>
						<th style="width:100%;">ชื่อบัญชี</th>
						<th style="width:100px;">หน้าบัญชี</th>
						<th style="width:100px;">เดบิต</th>
						<th style="width:100px;">เครดิต</th>
					</tr>
					<?php $sum['debit'] = 0 ?>
					<?php $sum['credit'] = 0 ?>
					<?php foreach ($earning as $debit): ?>
					<tr>
						<td class="dr1">
							<?php echo get_one('name','accounts','id',$debit['id']) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$debit['id']) ?></td>
						<td class="num"><?php echo number_format($debit['price'],2) ?></td>
						<td></td>
					</tr>
					<?php $sum['debit'] += $debit['price'] ?>
					<?php endforeach; ?>
					
					<?php if($result < 0): ?>
					<tr>
						<td class="dr1">
							<?php echo get_one('name','accounts','id',$low_height) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height) ?></td>
						<td class="num"><?php echo number_format($result * -1,2) ?></td>
						<td></td>
					</tr>
					<?php $sum['debit'] += $result ?>
					<?php endif ?>
					
					<?php foreach ($cost as $credit): ?>
					<tr>
						<td class="cr1">
							<?php echo $credit['account_name'] ?>
						</td>
						<td><?php echo $credit['account_code'] ?></td>
						<td></td>
						<td class="num"><?php echo number_format($credit['price'],2) ?></td>
					</tr>
					<?php $sum['credit'] += $credit['price'] ?>
					<?php endforeach; ?>
					
					<?php if($result > 0): ?>
					<tr>
						<td class="cr1">
							<?php echo get_one('name','accounts','id',$low_height) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height) ?></td>
						<td></td>
						<td class="num"><?php echo number_format($result,2) ?></td>
					</tr>
					<?php $sum['credit'] += $result ?>
					<?php endif ?>
					
					<tr>
						<th id="error"></td>
						<th>รวม</th>
						<th class="num"><?php echo number_format($sum['debit'],2) ?></th>
						<th class="num"><?php echo number_format($sum['credit'],2) ?></th>
					</tr>
				</table>
				</div>
			</th>
		</tr>
		<tr><th>คำอธิบาย</th><td><?php echo ($voucher1['description'])?nl2br($voucher1['description']):'-' ?></td></tr>
		<tr>
			<th></th>
			<td>
				<a class="button" href="voucher/close/save/<?php echo $fund['id'] ?>"><span class="icon_text save"></span>บันทึก</a>
				<a class="button" rel="back" href="#"><span class="icon_text goback"></span>ย้อนกลับ</a> 
			</td>
		</tr>
	</table>
	</div>
	<div id="tab2">
	<table class="form">
		<tr><th>วันเดือนปีที่ลงบัญชี</th><td><?php echo db_to_th($voucher2['voucher_date']) ?></td></tr>
		<tr><th>เลขที่</th><td><?php echo $voucher2['number'] ?></td></tr>
		<tr>
			<th>ประเภท</th>
			<td>
				<?php echo ($voucher2['voucher_type_id']==1)?'ด้านรับ':'' ?>
				<?php echo ($voucher2['voucher_type_id']==2)?'ด้านจ่าย':'' ?>
				<?php echo ($voucher2['voucher_type_id']==3)?'ด้านทั่วไป':'' ?>
			</td>
		</tr>
		<tr><th>รายการการลงบัญชี</th><td class="voucher_match"></td></tr>
		<tr>
			<th colspan="2" style="background:#EEE;">
				<div id="voucher_match">
				<table class="tbform">
					<tr>
						<th style="width:100%;">ชื่อบัญชี</th>
						<th style="width:100px;">หน้าบัญชี</th>
						<th style="width:100px;">เดบิต</th>
						<th style="width:100px;">เครดิต</th>
					</tr>
					<?php $sum['debit'] = 0 ?>
					<?php $sum['credit'] = 0 ?>
					
					<?php if($result > 0): ?>
					<tr>
						<td class="dr1">
							<?php echo get_one('name','accounts','id',$low_height) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height) ?></td>
						<td class="num"><?php echo number_format($result,2) ?></td>
						<td></td>
					</tr>
					<tr>
						<td class="cr1">
							<?php echo get_one('name','accounts','id',$low_height_total) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height_total) ?></td>
						<td></td>
						<td class="num"><?php echo number_format($result,2) ?></td>
					</tr>

					<?php endif ?>
		
					
					<?php if($result < 0): ?>
					<tr>
						<td class="dr1">
							<?php echo get_one('name','accounts','id',$low_height_total) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height_total) ?></td>
						<td class="num"><?php echo number_format($result * -1,2) ?></td>
						<td></td>
					</tr>
					<tr>
						<td class="cr1">
							<?php echo get_one('name','accounts','id',$low_height) ?>
						</td>
						<td><?php echo get_one('code','accounts','id',$low_height) ?></td>
						<td></td>
						<td class="num"><?php echo number_format($result * -1,2) ?></td>
					</tr>
					<?php endif ?>
					
		
					
					<tr>
						<th id="error"></td>
						<th>รวม</th>
						<th class="num"><?php echo number_format($result,2) ?></th>
						<th class="num"><?php echo number_format($result,2) ?></th>
					</tr>
				</table>
				</div>
			</th>
		</tr>
		<tr><th>คำอธิบาย</th><td><?php echo ($voucher2['description'])?nl2br($voucher2['description']):'-' ?></td></tr>
		<tr>
			<th></th>
			<td>
				<a class="button" href="voucher/close/save/<?php echo $fund['id'] ?>"><span class="icon_text save"></span>บันทึก</a>
				<a class="button" rel="back" href="#"><span class="icon_text goback"></span>ย้อนกลับ</a> 
			</td>
		</tr>
	</table>
	</div>
</div>